-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ensure correct log message from ETL overseer. #1490
Conversation
The php type engine gets confused when you try to string convert an iAction object in the Logger code. Possibly something to do with the way the class is constructed or the loader???? Anyway the old code results in the iAction object being treated as an Array like object in the classes/CCR/CCRLineFormatter.php on line 44. This change ensures a string is sent to the logger since that is what we want.
So I believe I've found the root problem that was causing this behavior. In if (is_array($record)) {
return json_encode($record);
} This code is the reason that a PHP Warning about an Array to String conversion is thrown in Here's an example: Given the following logger call $logger->info(array(
'message' => 'start',
'action_name' => $actionName,
'action' => $actionObj,
'start_date' => $overseerOptions->getStartDate(),
'end_date' => $overseerOptions->getEndDate(),
)); the result of {
"message":"start",
"action_name":"db-model-test.create-table",
"action":{},
"start_date":null,
"end_date":null
} Note the empty When this data get's to So there's a couple of different ways I've thought of that we can fix this:
protected function extractMessage($record)
{
if (is_array($record)) {
while (list($key, $value) = each($record)) {
if (is_object($value)) {
$record[$key] = (string) $value;
}
}
return json_encode($record);
}
return json_encode(array('message' => $record));
} Thus making sure that we don't lose any information about objects that can be converted to strings.
Thoughts? |
@jpwhite4 So a quick update, I was going back through the PHP7 & MariaDB updates and it turns out that, when running on Centos8, I need to include the changes to The problem I ran into was when running the DBModelTest component tests they all would error out with |
This change was necessary after running into a problem w/ running the component tests on Centos8. Specifically, the DBModelTest tests began throwing a PHP error for attempting to cast an array to string. Having run into this while testing / researching ubccr#1490 I implemented one of the proposed fixes for that PR here which resolved the errors.
We ran into a problem described in this PR: ubccr#1490 After some research I found that the root of the problem is this function json_encode'ing `$record` when the contents of `$record` may contain objects that do not support `JsonSerializable` but that do implement `toString()`. After a conversation w/ Joe it's been decided that our Logging API will be to support the logging of arrays w/ objects that implement a `toString()` function. The eagle-eyed may notice that this solution differs from the one I put forth in the above PR. The reason being that the original solution only supported the use case of having an array w/ top level value objects and would not work as expected if a nested array is supplied with an object that implements `toString()`.
This pull request is superseded by the #1493 |
) * Updating the logging code to not throw away all class information We ran into a problem described in this PR: #1490 After some research I found that the root of the problem is this function json_encode'ing `$record` when the contents of `$record` may contain objects that do not support `JsonSerializable` but that do implement `toString()`. After a conversation w/ Joe it's been decided that our Logging API will be to support the logging of arrays w/ objects that implement a `toString()` function. The eagle-eyed may notice that this solution differs from the one I put forth in the above PR. The reason being that the original solution only supported the use case of having an array w/ top level value objects and would not work as expected if a nested array is supplied with an object that implements `toString()`. * Adding Additional Documentation Per @jpwhite4, it's important that we document that our Logger supports logging both strings and arrays, and if an array is provided that contains objects, those objects will be converted to strings via the `__toString` function. Co-authored-by: Ryan Rathsam <[email protected]>
The php type engine gets confused when you try to string convert an
iAction object in the Logger code. Possibly something to do with the way
the class is constructed or the loader????
Anyway the old code results in the iAction object being treated as an
Array like object in the classes/CCR/CCRLineFormatter.php on line 44.
This change ensures a string is sent to the logger since that is
what we want.